package com.sharer.last.controller;

import com.sharer.last.base.constant.CommonConstant;
import com.sharer.last.base.model.PageVO;
import com.sharer.last.base.model.R;
import com.sharer.last.model.dto.log.VisitLogQueryDTO;
import com.sharer.last.model.vo.log.VisitLogVO;
import org.springframework.web.bind.annotation.*;
import com.sharer.last.service.VisitLogService;

import javax.annotation.Resource;

/**
 * 访问日志后台管理
 *
 * @ClassName VisitLogController
 * @Author wangjin
 * @Date 2023/5/5 21:05
 * @Description
 * @Version 1.0
 */
@RestController
@RequestMapping(CommonConstant.BLOG_ADMIN_API + "/visit/log")
public class VisitLogController {
    @Resource
    VisitLogService visitLogService;

    /**
     * 分页查询访问日志列表
     *
     * @param visitLogDTO
     * @return
     */
    @PostMapping("/page")
    public R<PageVO<VisitLogVO>> page(@RequestBody VisitLogQueryDTO visitLogDTO) {
        PageVO<VisitLogVO> pageList = visitLogService.selectListByPage(visitLogDTO);
        return R.success(pageList);
    }

    /**
     * 按id删除访问日志
     *
     * @param id 日志id
     * @return
     */
    @DeleteMapping("/delete")
    public R delete(@RequestParam Long id) {
        visitLogService.removeVisitLogById(id);
        return R.handle();
    }
}
